<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
        //优先级队列
      function priQueue() {
        //每一个节点都是一个对象 所有用一个数组来存每一个节点
        this.item = [];
        //构建每一个节点
        function QueueElement(val, pri) {
          this.val = val;
          this.pri = pri;
        }

        priQueue.prototype.enqueue = function (val, pri) {
          var queueElement = new QueueElement(val, pri);
          this.item.push(queueElement);
        };
        priQueue.prototype.toString = function () {
          var res = "";
          for (let index = 0; index < this.item.length; index++) {
            res += this.item[index].val + "-" + this.item[index].pri;
          }
          return res;
        };
      }

      var priqueue = new priQueue();
      priqueue.enqueue("第一个元素", "我的pri为10");
      console.log(priqueue.toString());
    </script>
  </body>
</html>
